from django import template

register = template.Library()

@register.filter(name='percentage')
def percentage(fraction, population):
    """
    percentage tag, ukradeno sa http://www.jongales.com/blog/2009/10/19/percentage-django-template-tag/
    """
    try:
        if float(population) == 0:
            return "%.2f%%" % (0)
        else:
            return "%.2f%%" % ((float(fraction) / float(population)) * 100)
    except ValueError:
        return ''